home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / COMPTOOL / ACTVCOMP / COFFEE / MTCMOD1.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-11-27  |  1.4 KB  |  42 lines

  1. Attribute VB_Name = "modMT"
  2. Option Explicit
  3.  
  4. ' This module demonstrates that Visual Basic
  5. '   creates a separate instance of global data
  6. '   for each thread.  Thus, the glngGlobalData
  7. '   variable will have a separate value for
  8. '   each thread Visual Basic starts.
  9. '
  10. ' This fact is used to keep a count of Coffee
  11. '   objects on each thread:  In the Coffee
  12. '   object's Initialize event, it adds one to
  13. '   glngGlobalData; in its Terminate event,
  14. '   it subtracts one.
  15. '
  16. ' Any Coffee object can then find out how
  17. '   many Coffee objects are on its thread by
  18. '   testing glngGlobalData.  Clients can also
  19. '   find out by calling the NumberOnThread
  20. '   method, which returns glngGlobalData.
  21. '
  22. ' When MTCoffee is run in the development
  23. '   environment, where there's only a single
  24. '   thread, NumberOnThread is the total number
  25. '   of Coffee objects.  When MTCoffee is
  26. '   compiled with Thread Per Object selected,
  27. '   the count will be one (1) for each Coffee
  28. '   object, unless you call GetCoffeeOnSameThread
  29. '   to create a second Coffee on the thread.
  30. '
  31. ' When MTCoffee is compiled with thread pooling,
  32. '   NumberOnThread will be greater than one
  33. '   on some thread whenever the number of
  34. '   active Coffee objects is greater than
  35. '   the number of threads in the pool.
  36. '
  37. ' This subject is covered in "Scalability and
  38. '   Multithreading," in Books Online.
  39.  
  40. Public glngGlobalData As Long
  41.  
  42.